<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>蔬菜商城首页</title>
    <style>
        /* 全局样式重置 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
            background-color: #f8faf5;
            overflow-x: hidden;
        }

        /* 页面整体容器 - 固定高度分区 */
        .page-container {
            display: flex;
            flex-direction: column;
            min-height: 100vh; /* 占满视口高度 */
        }

        /* 上半部分：轮播图区域 - 固定60%视口高度 */
        .carousel-section {
            height: 60vh;
            position: relative;
            overflow: hidden;
            background-color: #f0f0f0; /* 背景色防止图片加载前留白 */
        }

        /* 轮播图核心容器 */
        .carousel {
            width: 100%;
            height: 100%;
        }

        .carousel-inner {
            display: flex;
            height: 100%;
            transition: transform 0.5s ease-in-out;
        }

        .carousel-item {
            min-width: 100%;
            height: 100%;
        }

        .carousel-item img {
            width: 100%;
            height: 100%;
            object-fit: cover; /* 强制覆盖容器，保持比例 */
        }

        /* 轮播控制按钮 */
        .carousel-control {
            position: absolute;
            top: 50%;
            transform: translateY(-50%);
            width: 40px;
            height: 40px;
            border: none;
            border-radius: 50%;
            background-color: rgba(0, 0, 0, 0.3);
            color: white;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 10;
            transition: background-color 0.3s;
        }

        .carousel-control:hover {
            background-color: rgba(0, 0, 0, 0.6);
        }

        .carousel-control.prev {
            left: 20px;
        }

        .carousel-control.next {
            right: 20px;
        }

        /* 轮播指示器 */
        .carousel-indicators {
            position: absolute;
            bottom: 20px;
            left: 50%;
            transform: translateX(-50%);
            display: flex;
            gap: 8px;
            z-index: 10;
        }

        .carousel-indicators button {
            width: 12px;
            height: 12px;
            border-radius: 50%;
            border: none;
            background-color: rgba(255, 255, 255, 0.5);
            cursor: pointer;
            transition: background-color 0.3s;
        }

        .carousel-indicators button.active {
            background-color: white;
        }

        /* 下半部分：文字区域 - 固定40%视口高度 */
        .text-section {
            height: 40vh;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 0 50px;
            background-color: #fff;
        }

        .text-content {
            max-width: 800px;
            text-align: center;
        }

        .text-content h2 {
            font-size: 28px;
            color: #469b57;
            margin-bottom: 15px;
            font-weight: 600;
        }

        .text-content p {
            font-size: 16px;
            line-height: 1.8;
            color: #666;
            margin-bottom: 20px;
        }

        /* 登录按钮 */
        .login-btn {
            display: inline-block;
            padding: 12px 36px;
            background-color: #469b57;
            color: white;
            text-decoration: none;
            border-radius: 30px;
            transition: all 0.3s ease;
            font-weight: 500;
        }

        .login-btn:hover {
            background-color: #3a874b;
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(70, 155, 87, 0.2);
        }

        /* 响应式适配 - 小屏幕调整 */
        @media (max-width: 768px) {
            .carousel-section {
                height: 50vh; /* 小屏幕轮播图占50% */
            }

            .text-section {
                height: 50vh; /* 文字区占50% */
                padding: 0 30px;
            }

            .text-content h2 {
                font-size: 24px;
            }
        }
    </style>
</head>

<body>

<!-- 页面整体容器 -->
<div class="page-container">
    <!-- 上半部分：轮播图区域 -->
    <section class="carousel-section">
        <div class="carousel" id="mainCarousel">
            <div class="carousel-inner" id="carouselInner">
                <!-- 轮播图片，可根据需要添加更多 .carousel-item -->
                <div class="carousel-item active">
                    <img src="../static/images/sc-002.png" alt="新鲜蔬菜轮播图1">
                </div>
                <div class="carousel-item">
                    <img src="../static/images/sc-003.png" alt="新鲜蔬菜轮播图2">
                </div>
                <div class="carousel-item">
                    <img src="../static/images/sc-004.png" alt="新鲜蔬菜轮播图3">
                </div>
            </div>

            <!-- 轮播控制按钮 -->
            <button class="carousel-control prev" onclick="prevSlide()">
                <span>&lt;</span>
            </button>
            <button class="carousel-control next" onclick="nextSlide()">
                <span>&gt;</span>
            </button>

            <!-- 轮播指示器 -->
            <div class="carousel-indicators" id="carouselIndicators">
                <button class="active" onclick="goToSlide(0)"></button>
                <button onclick="goToSlide(1)"></button>
                <button onclick="goToSlide(2)"></button>
            </div>
        </div>
    </section>

    <!-- 下半部分：文字区域 -->
    <section class="text-section">
        <div class="text-content">
            <h2>鲜采蔬菜，趣享健康</h2>
            <p>在「蔬趣天地」，每一颗蔬菜都饱含阳光与土地的馈赠。</p>
            <p>我们严选当季鲜蔬，从田园直抵您家，锁住自然本味。</p>
            <a href="login" class="login-btn">立即进入</a>
        </div>
    </section>
</div>

<script>
    // 轮播图核心逻辑
    let currentSlide = 0;
    const slides = document.querySelectorAll('.carousel-item');
    const indicators = document.querySelectorAll('#carouselIndicators button');
    const carouselInner = document.getElementById('carouselInner');
    const slideCount = slides.length;

    // 更新轮播图显示
    function updateCarousel() {
        carouselInner.style.transform = `translateX(-${currentSlide * 100}%)`;
        indicators.forEach((indicator, index) => {
            indicator.classList.toggle('active', index === currentSlide);
        });
    }

    // 下一张
    function nextSlide() {
        currentSlide = (currentSlide + 1) % slideCount;
        updateCarousel();
    }

    // 上一张
    function prevSlide() {
        currentSlide = (currentSlide - 1 + slideCount) % slideCount;
        updateCarousel();
    }

    // 跳转到指定幻灯片
    function goToSlide(index) {
        currentSlide = index;
        updateCarousel();
    }

    // 自动轮播（5秒切换一次）
    let autoplay = setInterval(nextSlide, 5000);

    // 鼠标悬停暂停自动轮播
    document.getElementById('mainCarousel').addEventListener('mouseenter', () => {
        clearInterval(autoplay);
    });

    // 鼠标离开恢复自动轮播
    document.getElementById('mainCarousel').addEventListener('mouseleave', () => {
        autoplay = setInterval(nextSlide, 5000);
    });
</script>
</body>

</html>


